/*
* Valentine Gladstein
* SOLAR ID 108731583
* Homework #2
* CSE214
* Recitation 03-Phil Ammirato
* Grading TA: Yanjie LI
*/

import java.io.*;
import java.util.*;

public class CardInfo {
    //The CardInfo class sotres the information for a credit card.

    private String name;
    private String company;
    private String dateOpened;
    private double balance;
    private int status;


/**       
 * Constructor. Creates a new CardInfo object.
 * @param accountName: the name associated with the account
 * @param issuer: the company which issued the card
 * @param date: the date the card was opened
 * @param bal: the card's current balance.
 * @param stat: the status code currently asosciated with the card.
 */ 
    public CardInfo(String accountName, String issuer, String date, double bal, int stat) {
	try {
	    setName(accountName);
	} catch (InputTooLongException e){}
	try {
	    setCompany(issuer);
	} catch (InputTooLongException e){}
	setDateOpened(date);
	setBalance(bal);
	setStatus(stat);
    }


/**       
 * Default constructor. If no parameters are provided, it creates a new CardInfo object with generic parameters.
 */ 
    public CardInfo() {
	try {
	    setName("John Doe");
	} catch (InputTooLongException e){}
	try {
	    setCompany("Default");
	} catch (InputTooLongException e){}
	setDateOpened("01/01/1900");
	setBalance(0.0);
	setStatus(0);
    }

/**       
 * Returns a formatted string representation of the current CardInfo object.
 * @return:  a formatted string representation of the current CardInfo object.
 */ 
    public String toString() {
	String s = "\n";
s += String.format("%-25s%-14s%-10s%-10s%-6s", name, company, dateOpened, balance, status);
	return s;
    }

/**       
 * Returns a formatted string representation of the current CardInfo object.
 * @return:  a formatted string representation of the current CardInfo object.
 */ 
    public String getName() {
	return name;
    }

/**       
 * Returns the compnay asosciated with the card.
 * @return:  the compnay asosciated with the card.
 */ 
    public String getCompany(){
	return company;
    }

/**       
 * Returns the date the card was opened.
 * @return:  the date the card was opened.
 */  
    public String getDateOpened(){
	return dateOpened;
    }

/**       
 * Returns the card's balance
 * @return:  the card's balance.
 */
    public double getBalance(){
	return balance;
    }

/**       
 * Returns the status code asosciated with the card.
 * @return:  the status code asosciated with the card.
 */ 
    public int getStatus(){
	return status;
    }

/**       
 * Sets the name asosciated with the card.
 * @param accountName:  the name to be associated with the card.
 */ 
    public void setName(String accountName) throws InputTooLongException {
	if (accountName.length() > 25) {
	    System.out.println("Account name max length = 25 characters.");
	    setName(accountName.substring(0,24));
	    throw new InputTooLongException();
	}
	else name = accountName;
    }

/**       
 * Sets the compnay asosciated with the card.
 * @param issuer:  the company to be associated with the card.
 */ 
    public void setCompany(String issuer) throws InputTooLongException {
	if (issuer.length() > 15) {
	    System.out.println("Issuer name max length = 15 characters.");
	    setCompany(issuer.substring(0,14));
	    throw new InputTooLongException();
	}
	else company = issuer;
    }


    public void setDateOpened(String date) {
        dateOpened = date;
    }

    public void setBalance(double bal ) {
	balance = bal;
    }

    public void setStatus(int stat ) {
	status = stat;
    }

    public class InputTooLongException extends Exception {
	//This class creates a custom exception which is thrown when user input exceeds the maximum allowed string length.
        public InputTooLongException() {
        }
    }
}
